package com.example.check.service.serviceImpl;

import com.example.check.mapper.CheckHistoryMapper;
import com.example.check.pojo.CheckHistory;
import com.example.check.service.CheckHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 查验历史服务实现类
 */
@Service
public class CheckHistoryServiceImpl implements CheckHistoryService {
    
    @Autowired
    private CheckHistoryMapper checkHistoryMapper;
    
    @Override
    public CheckHistory getById(Integer id) {
        return checkHistoryMapper.selectById(id);
    }
    
    @Override
    public List<CheckHistory> getByTripId(Integer tripId) {
        return checkHistoryMapper.selectByTripId(tripId);
    }
    
    @Override
    public List<CheckHistory> getByUserId(Integer userId) {
        return checkHistoryMapper.selectByUserId(userId);
    }
    
    @Override
    public List<CheckHistory> getByItemId(Integer itemId) {
        return checkHistoryMapper.selectByItemId(itemId);
    }
    
    @Override
    public boolean add(CheckHistory checkHistory) {
        checkHistory.setCreatedAt(LocalDateTime.now());
        return checkHistoryMapper.insert(checkHistory) > 0;
    }
    
    @Override
    public boolean update(CheckHistory checkHistory) {
        return checkHistoryMapper.update(checkHistory) > 0;
    }
    
    @Override
    public boolean deleteById(Integer id) {
        return checkHistoryMapper.deleteById(id) > 0;
    }
    
    @Override
    public boolean deleteByItemId(Integer itemId) {
        return checkHistoryMapper.deleteByItemId(itemId) > 0;
    }
    
    @Override
    public boolean deleteByTripId(Integer tripId) {
        return checkHistoryMapper.deleteByTripId(tripId) > 0;
    }
    
    @Override
    public int countByTripId(Integer tripId) {
        return checkHistoryMapper.countByTripId(tripId);
    }
}




